package org.iabako.shared.entity.business;

import com.google.gwt.user.client.rpc.GwtTransient;
import org.hibernate.annotations.Index;
import org.iabako.shared.entity.enumeration.PriceUnit;
import org.iabako.shared.entity.enumeration.ProductType;
import org.iabako.shared.entity.user.Enterprise;
import org.iabako.shared.entity.user.User;

import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
 * Created by jose on 16/01/15.
 */

@Entity
@Table(name = "PRODUCT")
public class Product extends BusinessEntity implements Serializable {

    @Id
    @GeneratedValue
    @Column(name = "ID")
    private Long id;

    @Column(name = "NUMBER", nullable = false)
    @Index(name = "NUMBER")
    @NotNull
    private String number;

    @Column(name = "NAME", nullable = false)
    @Index(name = "NAME")
    @NotNull
    private String name;

    @Column(name = "DESCRIPTION", nullable = false, length = 1000)
    @NotNull
    private String description;

    @Column(name = "PRODUCT_TYPE", nullable = false)
    @NotNull
    @Enumerated(EnumType.STRING)
    private ProductType productType;

    @Column(name = "PURCHASE_PRICE")
    private Double purchasePrice;

    @Column(name = "PRICE", nullable = false)
    @NotNull
    private Double price;

    @Column(name = "PRICE_UNIT", nullable = false)
    @NotNull
    @Enumerated(EnumType.STRING)
    private PriceUnit priceUnit;

    @Column(name = "TAX_PERCENT")
    @Max(100)
    private Double taxPercent;

    @Column(name = "QUANTITY", nullable = false)
    private double quantity;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ID_ENTERPRISE", nullable = false)
    @GwtTransient
    private Enterprise enterprise;

    @Column(name = "EXTERNAL_LINK_NAME")
    private String externalLinkName;

    @Column(name = "EXTERNAL_LINK_URL")
    private String externalLinkUrl;

    @Column(name = "CREATION_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationDate;

    @Column(name = "LAST_MODIFICATION_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastModificationDate;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ID_LAST_MODIFICATION_USER")
    @GwtTransient
    private User lastModificationUser;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public ProductType getProductType() {
        return productType;
    }

    public void setProductType(ProductType productType) {
        this.productType = productType;
    }

    public Double getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(Double purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public PriceUnit getPriceUnit() {
        return priceUnit;
    }

    public void setPriceUnit(PriceUnit priceUnit) {
        this.priceUnit = priceUnit;
    }

    public Double getTaxPercent() {
        return taxPercent;
    }

    public void setTaxPercent(Double taxPercent) {
        this.taxPercent = taxPercent;
    }

    public double getQuantity() {
        return quantity;
    }

    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getExternalLinkName() {
        return externalLinkName;
    }

    public void setExternalLinkName(String externalLinkName) {
        this.externalLinkName = externalLinkName;
    }

    public String getExternalLinkUrl() {
        return externalLinkUrl;
    }

    public void setExternalLinkUrl(String externalLinkUrl) {
        this.externalLinkUrl = externalLinkUrl;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public Date getLastModificationDate() {
        return lastModificationDate;
    }

    public void setLastModificationDate(Date lastModificationDate) {
        this.lastModificationDate = lastModificationDate;
    }

    public User getLastModificationUser() {
        return lastModificationUser;
    }

    public void setLastModificationUser(User lastModificationUser) {
        this.lastModificationUser = lastModificationUser;
    }

    @Override
    public void copyDatesAsString() {

    }
}
